/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amit.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author amit
 */
public class Reflection {

    public static String getStringFromFields(Class theClass, Object object) {
        Field[] fields = theClass.getFields();
        String toReturn = "";
        for (Field field : fields) {
            try {
                toReturn += (field.getName() + " - " + field.get(object)) + " ";
            } catch (Exception ex) {
                Logger.getLogger(Reflection.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return toReturn;
    }

    public static Object callMethod(Object theObject, String methodName,Class[] paramTypes, Object[] params) throws Exception{
        Method m = theObject.getClass().getMethod(methodName, paramTypes);
        return m.invoke(theObject, params);
    }
}
